﻿using Skying.Reflection.Update;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Serialization;

namespace UpdateServer
{
	/// <summary>
	/// UpdateUriHandler의 요약 설명입니다.
	/// </summary>
	public class UpdateUriHandler : IHttpHandler
	{
		public void ProcessRequest(HttpContext context)
		{
			context.Response.ContentType = "text/xml";

			UpdateSchema updateXml = new UpdateSchema();

			updateXml.Gateway = new UpdateSchemaGateway[3];

			updateXml.Gateway[0] = new UpdateSchemaGateway()
			{
				Id = "0A22D6BE-AA7A-47A0-B935-ADD701166F3E",
				TargetType = Enum.GetName(typeof(UpdateTargetTypes), UpdateTargetTypes.WindowsApplicationManifest),
				CheckUri = "http://localhost:8081/MediaScreenClient.exe.manifest",
				UpdateUri = "http://localhost:8081/MediaScreenClient.zip"
			};

			updateXml.Gateway[1] = new UpdateSchemaGateway()
			{
				Id = "FCAD782D-8849-48B3-A337-71F57E2E7C77",
				TargetType = Enum.GetName(typeof(UpdateTargetTypes), UpdateTargetTypes.AdobeAirApplication),
				CheckUri = "http://localhost:8081/ClientManager.xml",
				UpdateUri = "http://localhost:8081/ClientManager.zip"
			};

			updateXml.Gateway[2] = new UpdateSchemaGateway()
			{
				Id = "37C73B37-88D2-46B5-8A84-927208C7570E",
				TargetType = Enum.GetName(typeof(UpdateTargetTypes), UpdateTargetTypes.AdobeAirApplication),
				CheckUri = "http://localhost:8081/MediaScreenLauncher.xml",
				UpdateUri = "http://localhost:8081/MediaScreenLauncher.zip"
			};

			XmlSerializer serializer = new XmlSerializer(typeof(UpdateSchema));

			serializer.Serialize(context.Response.OutputStream, updateXml);
		}

		public bool IsReusable
		{
			get
			{
				return false;
			}
		}
	}
}